﻿using UnityEngine;

using System.Collections;



public class DoorScript : BaseUsableObject {
	

	public float speed = -1.0F;
	public float Cspeed = 1.0F;
	public float open, closed;
	bool closing = false;
	bool opening = false;
	bool openState = false;
	
	override public void use(GameObject user){
		if (openState) {
			closing = true;
			opening = false;
		} else {
			closing = false;
			opening = true;
		}
		openState = !openState;
	}
	
	void Update (){
		if (opening == true)
			transform.Translate(0, speed*Time.deltaTime, 0);

		if (transform.position.y <= open)
		{
			opening = false;
			transform.position = new Vector3(transform.position.x, open, transform.position.z);
		}

		if (closing == true)
			transform.Translate(0, Cspeed*Time.deltaTime, 0);

		if (transform.position.y >= closed)
		{
			closing = false;
			transform.position = new Vector3(transform.position.x, closed, transform.position.z);
		}
		
	}
	
}